Cell重用
1 | @property (weak, nonatomic) IBOutlet UITableView *myTableView; |
总之在复用的时候需要记住:
- 设置 Cell 的存在差异性的那些属性(包括样式和内容)时,有了 if 最好就要有 else,要显式的覆盖所有可能性。
- 设置 Cell 的存在差异性的那些属性时,代码要放在初始化代码块的外部。
tableView的组头/组尾重用
1 | - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section |
自定义HeaderFooterView
继承UITableViewHeaderFooterView,因为系统提供的UITableViewHeaderFooterView类有重用机制
1
2
3
4
5
6
7
8
9
10
11- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
self.contentView.backgroundColor = XMGCommonBgColor;
// label
UILabel *label = [[UILabel alloc] init];
self.label = label;
}
return self;
}注册自定义组头视图
1
2static NSString * const JPHeaderId = @"header";
[self.tableView registerClass:[JPCommentHeaderView class] forHeaderFooterViewReuseIdentifier:JPHeaderId];实现代理方法,返回组头视图
1 | - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section |
iOS 高性能异构滚动视图构建方案 —— LazyScrollView
http://pingguohe.net/2016/01/31/lazyscroll.html
http://stackoverflow.com/questions/20188049/uitableview-headerviewforsection-returns-null
How to implement UIScrollView with 1000+ subviews?
pagination and reusing views in scrollview
How to reuse UIView like UITableViewCell
UIScrollView极限优化:两个UIImageView循环利用